package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.ExchangeTbReq;
import com.ydkj.a37e_mall.Classes.Model.Request.GetTreasureReq;
import com.ydkj.a37e_mall.Classes.Model.Request.TreasureRecordReq;
import com.ydkj.a37e_mall.Classes.Model.Response.GetTreasureResp;
import com.ydkj.a37e_mall.Classes.Model.Response.TreasureRecordResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.MyExpandableListView;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;

import static com.ydkj.a37e_mall.R.id.business_tb_ptrscrollview;

/**
 * Created by Administrator on 2017/1/18.
 * 工资通宝
 */

public class WagesTbActivity extends BaseActivity implements View.OnClickListener {
    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private ImageView img_back;
    private TextView tv_wages_tb_money;
    private RelativeLayout rly_wages_tb_title;
    private LinearLayout lly_wages_tb_balance, lly_wages_tb_tb;
    private PullToRefreshScrollView ptr_wages_tb_scrollview;
    private MyExpandableListView my_wages_tb_expandablelv;
    private WagesTbAdapter wagesTbAdapter;
    private List<TreasureRecordResp.ResultEntity.DataEntity> gtouplist;
    private List<List<TreasureRecordResp.ResultEntity.DataEntity>> childlist;


    private PopupWindow transfermon_tb_Pop;
    private EditText et_pop_transfer_tb_num;//转通宝Pop的et
    private TextView tv_tramsfer_tb_balance, tv_tramsfer_tb_servicecharge, tv_tramsfer_tb_confirm, tv_pop_transfer_tb_icon, tv_pop_transfer_tb_text;   //转通宝Pop的tv
    private LinearLayout lly_pop_type1, lly_pop_type2;
    private ImageView img_pop_transfer_tb_down;   //转tbPop的img
    private int code;//判断转余额还是转通宝


    private PopupWindow transfermon_withdrawals_Pop;
    private EditText et_pop_withdrawals_name, et_pop_withdrawals_card, et_pop_withdrawals_num; //提现Pop的et
    private TextView tv_withdrawals_balance, tv_withdrawals_servicecharge, tv_withdrawals_confirm, tv_withdrawals_changecard;   //提现Pop的tv
    private ImageView img_pop_withdrawals_down;   //转帐Pop的img

    private String price;
    private String duty_fee;//服务费率

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wages_tb);
        mActivity = this;
        init();
        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.Af7261b), 0);

    }

    private void init() {

        myApplication = MyApplication.getInstance();
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);

        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        tv_wages_tb_money = (TextView) mActivity.findViewById(R.id.tv_wages_tb_money);

        rly_wages_tb_title = (RelativeLayout) mActivity.findViewById(R.id.rly_wages_tb_title);

        lly_wages_tb_balance = (LinearLayout) mActivity.findViewById(R.id.lly_wages_tb_balance);
        lly_wages_tb_tb = (LinearLayout) mActivity.findViewById(R.id.lly_wages_tb_tb);

        my_wages_tb_expandablelv = (MyExpandableListView) mActivity.findViewById(R.id.my_wages_tb_expandablelv);
        my_wages_tb_expandablelv.setGroupIndicator(null);
        my_wages_tb_expandablelv.setDivider(null);

        gtouplist = new ArrayList<>();
        childlist = new ArrayList<>();
        wagesTbAdapter = new WagesTbAdapter(gtouplist, childlist);
        my_wages_tb_expandablelv.setAdapter(wagesTbAdapter);

        TreasureRecord(REFRESH);

        ptr_wages_tb_scrollview = (PullToRefreshScrollView) mActivity.findViewById(R.id.ptr_wages_tb_scrollview);
        ptr_wages_tb_scrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        ptr_wages_tb_scrollview.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                GetTreasure();
                TreasureRecord(REFRESH);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                TreasureRecord(MORE);
            }
        });
        rly_wages_tb_title.setOnClickListener(this);
        lly_wages_tb_balance.setOnClickListener(this);
        lly_wages_tb_tb.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        WindowManager.LayoutParams lp;

        switch (view.getId()) {

            case R.id.lly_wages_tb_balance://转余额
                code = 2;
                showPopulwindow();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);

                transfermon_tb_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                break;
            case R.id.lly_wages_tb_tb://转通宝
                code = 1;
                showPopulwindow();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);

                transfermon_tb_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                InputMethodManager imm1 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
                imm1.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                break;
            case R.id.rly_wages_tb_title://提现
//                showPopulwindow3();
//                lp = getWindow().getAttributes();
//                lp.alpha = 0.5f;
//                getWindow().setAttributes(lp);
//                transfermon_withdrawals_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
//                InputMethodManager imm2 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
//                imm2.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                break;
        }

    }

    //获取我的通宝数量
    private void GetTreasure() {
        CustomProgressDialog.createDialog(mActivity).show();
        GetTreasureReq req = new GetTreasureReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setType("2");

        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                ptr_wages_tb_scrollview.onRefreshComplete();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "response==" + response);
                if (errno.equals("000")) {
                    GetTreasureResp resp = GsonImpl.get().toObject(response.toString(), GetTreasureResp.class);
                    tv_wages_tb_money.setText(resp.getResult().getData().getTreasure());
                    price = resp.getResult().getData().getTreasure();
                    duty_fee = resp.getResult().getData().getDuty_fee();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                ptr_wages_tb_scrollview.onRefreshComplete();
                CommonUtil.showToast(mActivity, "网络连接失败");

            }
        });
    }

    //通宝转换
    private void ExchangeTb(String amount, String intent) {
        CustomProgressDialog.createDialog(mActivity).show();
        ExchangeTbReq req = new ExchangeTbReq();
        req.setAmount(amount);
        req.setType("2");
        req.setIntent(intent);

        RequestParams params = new RequestParams();
        params.put("uuid", myApplication.getDataEntity().getUuid());
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        AsyncHttpClient httpClient = new AsyncHttpClient();
        httpClient.put(Const.COMMON_ADDRESS + req.urlString() + myApplication.getDataEntity().getUuid(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                transfermon_tb_Pop.dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "response==" + response);
                if (errno.equals("000")) {
                    transfermon_tb_Pop.dismiss();
                    CommonUtil.showToast(mActivity, errmsg);
                    GetTreasure();
                }

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                transfermon_tb_Pop.dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }

    //获取营业通宝的流水记录
    private void TreasureRecord(final int type) {
        TreasureRecordReq req = new TreasureRecordReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setType("2");
        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
            page = gtouplist.size() / 10 + 1;
        }
        req.setPage(page + "");
        req.setPage_size("10");
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
//                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("ssss", "通宝流水response==" + response);
                if (errno.equals("000")) {
                    TreasureRecordResp resp = GsonImpl.get().toObject(response.toString(), TreasureRecordResp.class);
                    if (type == LOAD || type == REFRESH) {
                        gtouplist.clear();
                        gtouplist.addAll(resp.getResult().getData());
                        for (int i = 0; i < gtouplist.size(); i++) {
                            List<TreasureRecordResp.ResultEntity.DataEntity> list = new ArrayList<TreasureRecordResp.ResultEntity.DataEntity>();
                            list.add(gtouplist.get(i));
                            childlist.add(list);
                        }
                    } else {

                        gtouplist.addAll(resp.getResult().getData());
                        for (int i = 0; i < gtouplist.size(); i++) {
                            List<TreasureRecordResp.ResultEntity.DataEntity> list = new ArrayList<TreasureRecordResp.ResultEntity.DataEntity>();
                            list.add(gtouplist.get(i));
                            childlist.add(list);
                        }
                    }
                    if (gtouplist.size() % 10 > 0) {
                        ptr_wages_tb_scrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        ptr_wages_tb_scrollview.setMode(PullToRefreshBase.Mode.BOTH);
                    }


                    wagesTbAdapter.notifyDataSetChanged();
                    ptr_wages_tb_scrollview.onRefreshComplete();

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }

    private class WagesTbAdapter extends BaseExpandableListAdapter {
        private List<TreasureRecordResp.ResultEntity.DataEntity> group;
        private List<List<TreasureRecordResp.ResultEntity.DataEntity>> child;


        public WagesTbAdapter(List<TreasureRecordResp.ResultEntity.DataEntity> group, List<List<TreasureRecordResp.ResultEntity.DataEntity>> child) {

            this.group = group;
            this.child = child;
        }

        @Override
        public int getGroupCount() {
            return group.size();
        }

        @Override
        public int getChildrenCount(int groupPosition) {
            return child.get(groupPosition).size();
        }

        @Override
        public TreasureRecordResp.ResultEntity.DataEntity getGroup(int groupPosition) {
            return group.get(groupPosition);
        }

        @Override
        public TreasureRecordResp.ResultEntity.DataEntity getChild(int groupPosition, int childPosition) {
            return child.get(childPosition).get(childPosition);
        }

        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }


        /**
         * 显示：group
         */
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                                 View convertView, ViewGroup parent) {
            ViewHolder vh;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.wagestb_group_list, null);
                vh = new ViewHolder();

                vh.img_group = (ImageView) convertView.findViewById(R.id.img_group);
                vh.img_wagestb_group_type = (ImageView) convertView.findViewById(R.id.img_wagestb_group_type);
                vh.img_wagestb_group_money = (TextView) convertView.findViewById(R.id.img_wagestb_group_money);
                vh.tv_wagestb_group_message = (TextView) convertView.findViewById(R.id.tv_wagestb_group_message);
                vh.tv_wagestb_group_time = (TextView) convertView.findViewById(R.id.tv_wagestb_group_time);


                convertView.setTag(vh);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            //箭头的切换
            if (isExpanded) {
                vh.img_group.setImageResource(R.mipmap.array_up);
            } else {
                vh.img_group.setImageResource(R.mipmap.array_down);
            }
            if (getGroup(groupPosition).getTurnover().equals("1")) {
                vh.img_wagestb_group_type.setBackground(getResources().getDrawable(R.mipmap.bank_add));
            } else {
                vh.img_wagestb_group_type.setBackground(getResources().getDrawable(R.mipmap.bank_rectangle_small));
            }

            vh.tv_wagestb_group_message.setText(getGroup(groupPosition).getType());
            vh.img_wagestb_group_money.setText(getGroup(groupPosition).getPrice());
            vh.tv_wagestb_group_time.setText(getGroup(groupPosition).getCreated_at());
            return convertView;

        }

        /**
         * 显示：child
         */
        @Override
        public View getChildView(int groupPosition, int childPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {
            ViewHolder vh;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.wagestb_child_list, null);
                vh = new ViewHolder();
                vh.tv_wagestb_child_order = (TextView) convertView.findViewById(R.id.tv_wagestb_child_order);
                vh.tv_wagestb_child_type = (TextView) convertView.findViewById(R.id.tv_wagestb_child_type);
                vh.tv_wagestb_child_store = (TextView) convertView.findViewById(R.id.tv_wagestb_child_store);
                vh.tv_wagestb_child_adress = (TextView) convertView.findViewById(R.id.tv_wagestb_child_adress);
                vh.tv_wagestb_child_phone = (TextView) convertView.findViewById(R.id.tv_wagestb_child_phone);

            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);

            vh.tv_wagestb_child_order.setText(child.get(groupPosition).get(childPosition).getSn());
            vh.tv_wagestb_child_store.setText(child.get(groupPosition).get(childPosition).getName());
            vh.tv_wagestb_child_adress.setText(child.get(groupPosition).get(childPosition).getAddress());
            vh.tv_wagestb_child_phone.setText(child.get(groupPosition).get(childPosition).getMobile());
            return convertView;
        }

        private class ViewHolder {
            private TextView img_wagestb_group_money, tv_wagestb_group_message, tv_wagestb_group_time;
            private ImageView img_group, img_wagestb_group_type;
            private TextView tv_wagestb_child_order, tv_wagestb_child_type, tv_wagestb_child_store, tv_wagestb_child_adress, tv_wagestb_child_phone;
        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return false;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }
    }


    //显示转账Pop
    private void showPopulwindow() {


        final View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_transfer_tb, null);

        img_pop_transfer_tb_down = (ImageView) contentView.findViewById(R.id.img_pop_transfer_tb_down);
        et_pop_transfer_tb_num = (EditText) contentView.findViewById(R.id.et_pop_transfer_tb_num);
        tv_tramsfer_tb_balance = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_balance);
        tv_tramsfer_tb_servicecharge = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_servicecharge);
        tv_tramsfer_tb_confirm = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_confirm);
        tv_pop_transfer_tb_icon = (TextView) contentView.findViewById(R.id.tv_pop_transfer_tb_icon);
        tv_pop_transfer_tb_text = (TextView) contentView.findViewById(R.id.tv_pop_transfer_tb_text);
        lly_pop_type1 = (LinearLayout) contentView.findViewById(R.id.lly_pop_type1);
        lly_pop_type2 = (LinearLayout) contentView.findViewById(R.id.lly_pop_type2);
        lly_pop_type2.setVisibility(View.GONE);
        transfermon_tb_Pop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        transfermon_tb_Pop.setTouchable(true);

        transfermon_tb_Pop.setAnimationStyle(R.style.mypopwindow_anim_style);

        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        transfermon_tb_Pop.setBackgroundDrawable(dw);
        transfermon_tb_Pop.setOutsideTouchable(true);
        transfermon_tb_Pop.setFocusable(true);

        //设置Pop不会被软键盘覆盖
//        transfermon_tb_Pop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
//        transfermon_tb_Pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        transfermon_tb_Pop.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.i("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
//        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.colorlorAccent));

        tv_tramsfer_tb_balance.setText("工资通宝： " + price);
        if (code == 1) {
            tv_pop_transfer_tb_icon.setText("工资通宝转通宝");
            tv_pop_transfer_tb_text.setText("转换成功后，可在我的通宝查询");
            tv_tramsfer_tb_balance.setText("工资通宝 ： " + price);


        } else if (code == 2) {

            tv_pop_transfer_tb_icon.setText("转为余额");
            tv_pop_transfer_tb_text.setText("转换成功后，可在我的余额查询");
            tv_tramsfer_tb_balance.setText("工资通宝 ： " + price);
        }


        transfermon_tb_Pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });


        //关闭Pop
        img_pop_transfer_tb_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                transfermon_tb_Pop.dismiss();
            }
        });


        et_pop_transfer_tb_num.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!editable.toString().equals("")) {
                    if (CommonUtil.isNumeric00(editable.toString())) {
                        Log.e("ssss", "11111===>" + editable.toString());
                        tv_tramsfer_tb_servicecharge.setText(CommonUtil.roundDouble(Double.parseDouble(editable.toString()) * Double.parseDouble(duty_fee), 2) + "");
                    } else {
                        Log.e("ssss", "2222===>" + editable.toString());
                        tv_tramsfer_tb_servicecharge.setText("");

                    }
                }
            }
        });

        //确认转账
        tv_tramsfer_tb_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (et_pop_transfer_tb_num.getText().toString().equals("")) {
                    return;
                }

                if (CommonUtil.isNumeric00(et_pop_transfer_tb_num.getText().toString())) {

                    if (Double.parseDouble(price) < Double.parseDouble(et_pop_transfer_tb_num.getText().toString())) {

                        CommonUtil.showToast(mActivity, "您的余额不足");

                    } else {
                        if (code == 2) {
                            //转余额
                            ExchangeTb(et_pop_transfer_tb_num.getText().toString(), code + "");

                        } else if (code == 1) {
                            //转通宝
                            ExchangeTb(et_pop_transfer_tb_num.getText().toString(), code + "");

                        }
                    }
                }


            }
        });
    }

    //提现
    private void showPopulwindow3() {

        View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_transfer_withdrawals, null);

        img_pop_withdrawals_down = (ImageView) contentView.findViewById(R.id.img_pop_withdrawals_down);

        et_pop_withdrawals_name = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_name);
        et_pop_withdrawals_card = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_card);
        et_pop_withdrawals_num = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_num);

        tv_withdrawals_balance = (TextView) contentView.findViewById(R.id.tv_withdrawals_balance);
        tv_withdrawals_servicecharge = (TextView) contentView.findViewById(R.id.tv_withdrawals_servicecharge);
        tv_withdrawals_confirm = (TextView) contentView.findViewById(R.id.tv_withdrawals_confirm);
        tv_withdrawals_changecard = (TextView) contentView.findViewById(R.id.tv_withdrawals_changecard);


        transfermon_withdrawals_Pop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        transfermon_withdrawals_Pop.setTouchable(true);

        transfermon_withdrawals_Pop.setAnimationStyle(R.style.mypopwindow_anim_style);

        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        transfermon_withdrawals_Pop.setBackgroundDrawable(dw);
        transfermon_withdrawals_Pop.setOutsideTouchable(true);
        transfermon_withdrawals_Pop.setFocusable(true);

        //设置Pop不会被软键盘覆盖
        transfermon_withdrawals_Pop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        transfermon_withdrawals_Pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        transfermon_withdrawals_Pop.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.i("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
//        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.colorAccent));

        transfermon_withdrawals_Pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });

        //关闭Pop
        img_pop_withdrawals_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                transfermon_withdrawals_Pop.dismiss();
            }
        });


        //确认转账
        tv_withdrawals_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        //更换银行卡
        tv_withdrawals_changecard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mActivity, MyBankcardActivity.class));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        GetTreasure();
    }


}
